home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / language / embedded / mcu / dtmf.arc / DTMF11.ASM < prev    next >
Assembly Source File  |  1989-12-17  |  4KB  |  152 lines

  1. * File: DTMF11.ASM
  2. * Driver routines for 68HC11 to produce DTMF tones in software
  3.  
  4. * this version uses a fixed 256 byte sine table, and a fixed 128 us sample time
  5. * this allows operation under interrupt control
  6.  
  7. * hardware requirements: 8 bit DAC on port b of 68HC11
  8. * To use, do a JSR to DTINIT to set up timer
  9. * then do a JSR to location DTMF with the digit in the lower nibble of
  10. * Accumulator A
  11. * digit values: 0-9, 10 = #, 11 = *, 12-15 represent a through d
  12. * A 60 ms tone burst will be generated, followed by 60 ms of silence
  13. * The location TTIME may be altered to change this timing
  14.  
  15.     asct
  16.  
  17. * First a few definitions
  18.  
  19. io    equ    $1000        offset for i/o registers
  20. deftt    equ    60        default tone time (60 ms)
  21. dac    equ    io+4        DAC output on port a
  22. tcnt    equ    io+$e        timer free running counter
  23. ocr1    equ    io+$16        output compare register
  24. tmsk1    equ    io+$22        int mask register
  25. tflg1    equ    io+$23        int flag register
  26. ocie    equ    $80        output compare interrupt enable
  27. intcnt    equ    128*2        count to load into output compare
  28.  
  29. row1    equ    23        row intervals
  30. row2    equ    25
  31. row3    equ    28
  32. row4    equ    31
  33.  
  34. col1    equ    40        column intervals
  35. col2    equ    44
  36. col3    equ    48
  37. col4    equ    54
  38.  
  39.     org    $0        RAM scratchpad - move this to fit your system
  40. ttime    rmb    1        tone time in milliseconds
  41. ttctr    rmb    2        time counter
  42. ttsave    rmb    2        save the count value for interdigit pause
  43. ttflag    rmb    1        non zero means generate tones
  44. rowptr    rmb    2        next row sample to load
  45. colptr    rmb    2        ditto for columns
  46. rowint    rmb    1        row interval - added to row counter each sample
  47. colint    rmb    1        ditto for column
  48. sample    rmb    1        temp storage for sample
  49.  
  50. * sine is the 256 byte sine wave table
  51. * this must be located on a page boundary! (ie lower 8 bits of address = 0)
  52.  
  53.     org    $1000
  54.  
  55.     include    sine56.asm
  56.  
  57. dtinit    ldaa    #deftt        set up time counter
  58.     staa    ttime
  59.     ldaa    #$80        set dac to halfway point
  60.     staa    dac
  61.     clr    ttflag        no tones please
  62.     sei            set up timer - first disable interrupts
  63.     ldd    tcnt        freeze counter
  64.     addd    #intcnt
  65.     std    ocr1
  66.     ldaa    #ocie
  67.     staa    tmsk1
  68.     staa    tflg1        clear flag if set
  69.     cli
  70.     rts            done for now
  71.  
  72. dtmf    anda    #$0f        clear out junk
  73.     tab            get row interval
  74.     ldx    #rowtab
  75.     abx
  76.     ldaa    ,x
  77.     staa    rowint
  78.     ldaa    rowtab-coltab,x    and column
  79.     staa    colint
  80.     ldd    #sine
  81.     std    rowptr        start at 0
  82.     std    colptr
  83.     ldaa    ttime        start tone - set time
  84.     ldab    #250        adjust for # of samples in (ttime) msec
  85.     mul            (125/128) * ttime * 4
  86.     lsrd
  87.     lsrd
  88.     lsrd
  89.     lsrd
  90.     lsrd
  91.     lsrd
  92.     std    ttsave        save for pause time
  93.     std    ttctr
  94.     inc    ttflag        start tones
  95. dtmf1    brset    ttflag,#1,dtmf1    loop till tone complete
  96.     ldd    ttsave        now do pause
  97.     std    ttctr
  98.     clr    rowint        do the pause by not moving pointers
  99.     clr    colint
  100.     inc    ttflag        start pause
  101. dtmf2    brset    ttflag,#0,dtmf2
  102.     rts            done
  103.  
  104. * timer interrupt service routine
  105. * if ttctr != 0, then output next sample to dac
  106.  
  107. tisr    ldd    ocr1        (5) add timer count
  108.     addd    #intcnt        (4)
  109.     std    ocr1        (5)
  110.     ldaa    #ocie        (2) clear flag
  111.     staa    tmsk1        (4)
  112.     brclr    ttflag,#1,tisr1    (6) don't generate tone if flag cleared
  113.     ldx    rowptr        (4) get next row sample
  114.     ldy    colptr        (5)
  115.     ldaa    ,y        (5) get column sample
  116.     asra            (2) divide by 4
  117.     asra            (2) divide by 4
  118.     adda    ,y        (5) now have 1.25 * column sample
  119.     adda    ,x        (4) add in row sample
  120.     eora    #$80        (2) fix sign bit
  121.     staa    dac        (4)
  122.     xgdx            (3) step to next lookup value - first row ...
  123.     addb    rowint        (3)
  124.     std    rowptr        (4)
  125.     xgdy            (4) ... then column ...
  126.     addb    colint        (3)
  127.     std    colptr        (4)
  128.     ldd    ttctr        (4) decrement timer
  129.     subd    #1        (4)
  130.     std    ttctr        (4)
  131.     bne    tisr1        (3) did count go to zero ?
  132.     clr    ttflag        ( ) yes - turn off tones
  133. tisr1    rti            (12)
  134. *                (12) interrupt response
  135. *                ===
  136. *                               119 cycles when generating tones
  137. *                total overhead at 2 MHz E clock = 119/256 == 46%
  138.  
  139. coltab    fcb    col2,col1,col2,col3    0,1,2,3
  140.     fcb    col1,col2,col3        4,5,6
  141.     fcb    col1,col2,col3        7,8,9
  142.     fcb    col1,col3        #,*
  143.     fcb    col4,col4,col4,col4    a,b,c,d
  144.  
  145. rowtab    fcb    row4,row1,row1,row1    0,1,2,3
  146.     fcb    row2,row2,row2        4,5,6
  147.     fcb    row3,row3,row3        7,8,9
  148.     fcb    row4,row4        #,*
  149.     fcb    row1,row2,row3,row4    a,b,c,d
  150.  
  151.     end
  152.